package YunNotes.allnotes.control;

import YunNotes.allnotes.dao.NoteDao;
import YunNotes.allnotes.model.Note;

import java.sql.SQLException;
import java.util.List;

/**
 * 控制层
 */
public class NoteAction {


    /**
     * 增加笔记
     */

    public void add(Note n) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.addNote(n);
    }

    /**
     * 设置分类
     */

    public void addLabel(String label, int num) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.addLabel(label, num);
    }

    /**
     * 设置分类顺序
     */

    public void addLabelNum(int labelNum, String label, int id) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.addLabelNum(labelNum, label, id);
    }

    /**
     * 修改笔记内容
     */

    public void upContent(String content, int num) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.updateContent(content, num);
    }

    /**
     * 修改笔记标题
     */

    public void updateHeadline(String headline, int num) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.updateHeadline(headline, num);
    }

    /**
     * 根据分类的名字，修改分类的顺序
     */

    public void updateLabelNum(int labelNum, String label, int id) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.updateLabelNum(labelNum, label, id);
    }

    /**
     * 删除分类（实则是讲label改为默认分类，讲LabelNum改为1）
     */

    public void delLabel(String label, int id) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.delLabel(label, id);
    }

    /**
     * 删除笔记
     */

    public void delNote(int num) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.delNote(num);
    }

    /**
     * 查询个人的所有笔记
     */

    public List<Note> query(int id) throws SQLException {
        NoteDao Dao = new NoteDao();
        return Dao.query(id);
    }

    /**
     * 关键字查询
     */

    public List<Note> key(int id, String key) throws SQLException {
        NoteDao Dao = new NoteDao();
        return Dao.key(id, key);
    }

    /**
     * 查询个人的所有分类
     */

    public List<Note> allLabel(int id) throws SQLException {
        NoteDao Dao = new NoteDao();
        return Dao.allLabel(id);
    }

    /**
     * 查询分类
     */

    public List<Note> searchByLabel(String label, int id) throws SQLException {
        NoteDao Dao = new NoteDao();
        return Dao.searchByLabel(label, id);
    }

    /**
     * 点赞和取消点赞
     */

    public void praise(int num, int id) throws SQLException {
        NoteDao Dao = new NoteDao();
        Dao.praise(num, id);
    }

    /**
     * 查询点赞数
     */

    public int queryPoints(int num) throws SQLException {
        NoteDao Dao = new NoteDao();
        return Dao.queryPoints(num);
    }

    public static void main(String[] args) throws SQLException {
        NoteAction noteAction = new NoteAction();

        System.out.println(noteAction.allLabel(1).toString());
    }

}
